# -*- coding: UTF-8 -*-
import configparser
import os


class MySQLConfig(object):
    host = ""
    mincached = 1
    maxcached = 5
    port = 3306
    user = ""
    password = ""
    database = ""
    charset = ""

    def __init__(self):
        config = self.__get_config()
        section = "MYSQL"
        self.host = config.get(section, "host")
        self.mincached = config.getint(section, "mincached")
        self.maxcached = config.getint(section, "maxcached")
        self.port = config.getint(section, "port")
        self.user = config.get(section, "user")
        self.password = config.get(section, "password")
        self.database = config.get(section, "database")
        self.charset = config.get(section, "charset")

    # 获取config配置文件
    @staticmethod
    def __get_config():
        # 其中 os.path.split(os.path.realpath(__file__))[0] 得到的是当前文件模块的目录
        path = os.path.split(os.path.realpath(__file__))[0] + '/sys.conf'
        config = configparser.ConfigParser()
        config.read(path)
        return config
